import java.util.List;

/**
 * 计算某一科全部人的平均分的实现类
 */
public class CourseAverageScoreCalculatorImpl implements CourseAverageScoreCalculator {
    @Override
    public double calculateCourseAverageScore(List<Grade> grades, String courseName) {
        double totalScore = 0;
        int count = 0;
        for (Grade grade : grades) {
            if (grade.getCourse().getCourseName().equals(courseName)) {
                totalScore += grade.getScore();
                count++;
            }
        }
        if (count > 0) {
            return (double) Math.round(totalScore / count * 100) / 100;
        }
        return 0;
    }
}    